package com.yanqu.road.dao.impl.activity.throwingPot;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.ThrowingPot;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

public class ActivityThrowingPotConfigDaoImpl extends TempDao {
    public Map<Integer, ThrowingPot> getThrowingPotConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, ThrowingPot> dataMap = new HashMap<>();
        String sql = "select * from t_s_activity_touhu_combination where activityId = ?";
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                ThrowingPot data = new ThrowingPot();

                data.setCombinationId(rs.getInt("combId"));

                data.setWeight(rs.getInt("weight"));

                data.setReward(rs.getString("rewards"));

                dataMap.put(rs.getInt("combId"), data);
            }
            return dataMap;
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
    }
}